package com.example.cslp.mapper;


import com.example.cslp.pojo.entity.Course;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
@Mapper
@Repository
public interface CourseMapperByYh {
    //创建课程
    @Insert("insert into courses(cover_image,name,description,course_type," +
            "price,video_url,material_url,discount,is_featured,uploader,upload_time,review_time,is_audited)" +
            "values (#{coverImage},#{name},#{description},#{courseType},#{price}," +
            "#{videoUrl},#{materialUrl},#{discount},#{isFeatured},#{uploader},#{uploadTime},#{reviewTime},#{isAudited})")
    Boolean createCourse(Course course);

    //查询所有课程
    @Select("select * from courses")
    List<Course> findAllCourse();

    //编辑已有课程
    @Update("UPDATE courses SET cover_image = #{coverImage}, name=#{name}, " +
            "description = #{description},course_type = #{courseType}, " +
            "price = #{price}, video_url = #{videoUrl}, material_url = #{materialUrl}, " +
            "discount = #{discount}, is_featured = #{isFeatured}  WHERE id = #{courseId}")
    Boolean editCourse(Course course);

    //删除课程
    @Delete("delete from courses where id=#{courseId}")
    Boolean delete(String courseId);

    //审核资料
    @Update("update material set is_audited=#{isAudited} where id=#{id}")
    Boolean examMaterial(Course course);

    //根据id获取课程
    @Select("select * from courses where id=#{courseId}")
    Course getCourseById(String courseId);
}
